Change in openvpn[master]: openvpnserv: Fix conversion warnings in interactive.c
A message that is not in the archive (sent off-list or not yet received): gerrit.1767808679000.I864cd4a718886f437b72e93d0286f90fcb73592b@...2715...
Attention is currently required from: plaisthos.
Hello plaisthos,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email
to review the following change.
Change subject: openvpnserv: Fix conversion warnings in interactive.c
......................................................................
openvpnserv: Fix conversion warnings in interactive.c
Mostly DWORD vs. size_t conversions where we have no choice but to cast.
---
M src/openvpnserv/interactive.c
1 file changed, 37 insertions(+), 31 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/1457/1
src/openvpnserv/interactive.c +37 -31
@@ -1383,10 +1383,20 @@return TRUE; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif +/** +* Return correct length for regex value to set for string +* +*/ +static DWORD +RegWStringLength (PCWSTR string) +{ +size_t length = (wcslen (string) +1 ) *sizeof (wchar_t); +if (length >UINT_MAX ) + { + length =UINT_MAX ; + } +return (DWORD )length; +}/** * Prepare DNS domain "SearchList" registry value, so additional
@@ -1413,7 +1423,7 @@return TRUE; } -DWORD size = (wcslen (list) +1 ) *sizeof (*list); +DWORD size =RegWStringLength (list);LSTATUS err =RegSetValueExW (key,L"InitialSearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1474,7 +1484,7 @@wcsncpy (list, domains,wcslen (domains) +1 ); } - size = (wcslen (list) +1 ) *sizeof (list[0 ]); + size =RegWStringLength (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1515,7 +1525,7 @@ goto out; } - size = (wcslen (list) +1 ) *sizeof (list[0 ]); + size =RegWStringLength (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1579,14 +1589,14 @@ }/* If the search list is back to its initial state reset it */ -if (wcsncmp (list, initial,wcslen (list)) ==0 ) +if (wcsncmp (list, initial, list_len) ==0 ) {ResetDnsSearchDomains (key);return ; } } - size = (list_len +1 ) *sizeof (list[0 ]); + size =RegWStringLength (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1729,9 +1739,9 @@* @param family internet address family to set the servers for * @param value the value to set the name servers to * -* @return DWORD NO_ERROR on success, a Windows error code otherwise +* @return NO_ERROR on success, a Windows error code otherwise */ -static DWORD +static LSTATUS SetNameServersValue (PCWSTR itf_id,short family,PCSTR value) {DWORD err;
@@ -1751,7 +1761,7 @@ goto out; } - err =RegSetValueExA (itf,"NameServer" ,0 ,REG_SZ , (PBYTE )value,strlen (value) +1 ); + err =RegSetValueExA (itf,"NameServer" ,0 ,REG_SZ , (PBYTE )value, (DWORD )strlen (value) +1 );if (err) { MsgToEventLog(M_SYSERR, L"%S: could not set name servers '%S' for %s family %d (%lu)",
@@ -1777,9 +1787,9 @@* @param family internet address family to set the servers for * @param addrs comma separated list of name server addresses * -* @return DWORD NO_ERROR on success, a Windows error code otherwise +* @return NO_ERROR on success, a Windows error code otherwise */ -static DWORD +static LSTATUS SetNameServers (PCWSTR itf_id,short family,PCSTR addrs) {return SetNameServersValue (itf_id, family, addrs);
@@ -1793,7 +1803,7 @@* * @return DWORD NO_ERROR on success, a Windows error code otherwise */ -static DWORD +static LSTATUS ResetNameServers (PCWSTR itf_id,short family) {return SetNameServersValue (itf_id, family,"" );
@@ -1807,7 +1817,7 @@int addr_len = msg->addr_len;/* sanity check */ -const size_t max_addrs =_countof (msg->addr); +const int max_addrs =_countof (msg->addr);if (addr_len > max_addrs) { addr_len = max_addrs;
@@ -1949,7 +1959,7 @@short family = families[i];/* Create a comma sparated list of addresses of this family */ -int offset =0 ; +size_t offset =0 ;char addr_list[NRPT_ADDR_SIZE *NRPT_ADDR_NUM ];for (int j =0 ; j <NRPT_ADDR_NUM && addresses[j][0 ]; j++) {
@@ -2085,9 +2095,9 @@size_t addr_len =strlen (pos); pos += addr_len; - s -= addr_len; + s -= (DWORD )addr_len; } - s =strlen (addrs) +1 ; + s = (DWORD )strlen (addrs) +1 ; }if (strchr (addrs,':' ))
@@ -2163,7 +2173,8 @@LSTATUS err =ERROR_FILE_NOT_FOUND ;const DWORD buf_size = *size; -const size_t glyph_size =sizeof (*domains); +const DWORD glyph_size =sizeof (*domains); +const DWORD buf_len = buf_size / glyph_size;PWSTR values[] = {L"SearchList" ,L"Domain" ,L"DhcpDomainSearchList" ,L"DhcpDomain" ,NULL };for (int i =0 ; values[i]; i++)
@@ -2178,7 +2189,6 @@* - convert comma separated list to MULTI_SZ */ PWCHAR pos = domains; -const DWORD buf_len = buf_size / glyph_size;while (TRUE) {/* Terminate the domain at the next comma */
@@ -2188,9 +2198,9 @@ *comma ='\0' ; } -size_t domain_len =wcslen (pos); -size_t domain_size = domain_len * glyph_size; -size_t converted_size = (pos - domains) * glyph_size; +DWORD domain_len = (DWORD )wcslen (pos); +DWORD domain_size = domain_len * glyph_size; +DWORD converted_size = (DWORD )(pos - domains) * glyph_size;/* Ignore itf domains which match a pushed search domain */ if (ListContainsDomain (search_domains, pos, domain_len))
@@ -2216,7 +2226,7 @@ domain_size += glyph_size;/* Space for the terminating zeros */ -size_t extra_size =2 * glyph_size; +const DWORD extra_size =2 * glyph_size;/* Check for enough space to convert this domain */ if (converted_size + domain_size + extra_size > buf_size)
@@ -2450,7 +2460,7 @@/* Set DNS Server address */ err =RegSetValueExA (rule_key,"GenericDNSServers" ,0 ,REG_SZ , (PBYTE )address, -strlen (address) +1 ); + (DWORD )strlen (address) +1 );if (err) { goto out;
@@ -2571,7 +2581,7 @@if (domains[0 ]) {size_t domains_len =strlen (domains); - dom_size = domains_len +2 ;/* len + the trailing NULs */ + dom_size = (DWORD )domains_len +2 ;/* len + the trailing NULs */ wide_domains =utf8to16_size (domains, dom_size); dom_size *=sizeof (*wide_domains);
@@ -2628,10 +2638,6 @@return err; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif -/** * Return the registry key where NRPT rules are stored *
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I864cd4a718886f437b72e93d0286f90fcb73592b
Gerrit-Change-Number: 1457
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Attention is currently required from: flichtenheld, plaisthos.
cron2 has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email )
Change subject: openvpnserv: Fix conversion warnings in interactive.c
......................................................................
Patch Set 3: Code-Review-1
(3 comments)
Patchset:
PS3:
Two comments, and I really think Heiko should have a look at these changes.
File src/openvpnserv/interactive.c:
http://gerrit.openvpn.net/c/openvpn/+/1457/comment/55b31c70_6a63bb5f?usp=email :
PS3, Line 1391: RegWStringLength(PCWSTR string)
I'd suggest to name that RegWStringSize() - d12fk has tried to make everything that is a "number of bytes in memory" named "xxxsize", and everything that is "length of glyphs in a whatever-string" a "xxxlength". So this would be a "size" function.
(Also for length inside the function, as soon as wcslen() is multiplied it's not longer a "length" in that terminology)
http://gerrit.openvpn.net/c/openvpn/+/1457/comment/6dd9276d_710aa1d2?usp=email :
PS3, Line 1744: static LSTATUS
why is that change? We have a DWORD err and return that?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I864cd4a718886f437b72e93d0286f90fcb73592b
Gerrit-Change-Number: 1457
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 08 Jan 2026 17:27:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: cron2, d12fk, flichtenheld, plaisthos.
Hello cron2, d12fk, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email
to look at the new patch set (#4).
The following approvals got outdated and were removed:
Code-Review-1 by cron2
Change subject: openvpnserv: Fix conversion warnings in interactive.c
......................................................................
openvpnserv: Fix conversion warnings in interactive.c
Mostly DWORD vs. size_t conversions where we have no choice but to cast.
---
M src/openvpnserv/interactive.c
1 file changed, 32 insertions(+), 26 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/1457/4
src/openvpnserv/interactive.c +32 -26
@@ -1383,10 +1383,20 @@return TRUE; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif +/** +* Return correct length for regex value to set for string +* +*/ +static DWORD +RegWStringSize (PCWSTR string) +{ +size_t length = (wcslen (string) +1 ) *sizeof (wchar_t); +if (length >UINT_MAX ) + { + length =UINT_MAX ; + } +return (DWORD )length; +}/** * Prepare DNS domain "SearchList" registry value, so additional
@@ -1413,7 +1423,7 @@return TRUE; } -DWORD size = (wcslen (list) +1 ) *sizeof (*list); +DWORD size =RegWStringSize (list);LSTATUS err =RegSetValueExW (key,L"InitialSearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1474,7 +1484,7 @@wcsncpy (list, domains,wcslen (domains) +1 ); } - size = (wcslen (list) +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1515,7 +1525,7 @@ goto out; } - size = (wcslen (list) +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1579,14 +1589,14 @@ }/* If the search list is back to its initial state reset it */ -if (wcsncmp (list, initial,wcslen (list)) ==0 ) +if (wcsncmp (list, initial, list_len) ==0 ) {ResetDnsSearchDomains (key);return ; } } - size = (list_len +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1751,7 +1761,7 @@ goto out; } - err =RegSetValueExA (itf,"NameServer" ,0 ,REG_SZ , (PBYTE )value,strlen (value) +1 ); + err =RegSetValueExA (itf,"NameServer" ,0 ,REG_SZ , (PBYTE )value, (DWORD )strlen (value) +1 );if (err) { MsgToEventLog(M_SYSERR, L"%S: could not set name servers '%S' for %s family %d (%lu)",
@@ -1807,7 +1817,7 @@int addr_len = msg->addr_len;/* sanity check */ -const size_t max_addrs =_countof (msg->addr); +const int max_addrs =_countof (msg->addr);if (addr_len > max_addrs) { addr_len = max_addrs;
@@ -1949,7 +1959,7 @@short family = families[i];/* Create a comma sparated list of addresses of this family */ -int offset =0 ; +size_t offset =0 ;char addr_list[NRPT_ADDR_SIZE *NRPT_ADDR_NUM ];for (int j =0 ; j <NRPT_ADDR_NUM && addresses[j][0 ]; j++) {
@@ -2085,9 +2095,9 @@size_t addr_len =strlen (pos); pos += addr_len; - s -= addr_len; + s -= (DWORD )addr_len; } - s =strlen (addrs) +1 ; + s = (DWORD )strlen (addrs) +1 ; }if (strchr (addrs,':' ))
@@ -2163,7 +2173,8 @@LSTATUS err =ERROR_FILE_NOT_FOUND ;const DWORD buf_size = *size; -const size_t glyph_size =sizeof (*domains); +const DWORD glyph_size =sizeof (*domains); +const DWORD buf_len = buf_size / glyph_size;PWSTR values[] = {L"SearchList" ,L"Domain" ,L"DhcpDomainSearchList" ,L"DhcpDomain" ,NULL };for (int i =0 ; values[i]; i++)
@@ -2178,7 +2189,6 @@* - convert comma separated list to MULTI_SZ */ PWCHAR pos = domains; -const DWORD buf_len = buf_size / glyph_size;while (TRUE) {/* Terminate the domain at the next comma */
@@ -2188,9 +2198,9 @@ *comma ='\0' ; } -size_t domain_len =wcslen (pos); -size_t domain_size = domain_len * glyph_size; -size_t converted_size = (pos - domains) * glyph_size; +DWORD domain_len = (DWORD )wcslen (pos); +DWORD domain_size = domain_len * glyph_size; +DWORD converted_size = (DWORD )(pos - domains) * glyph_size;/* Ignore itf domains which match a pushed search domain */ if (ListContainsDomain (search_domains, pos, domain_len))
@@ -2216,7 +2226,7 @@ domain_size += glyph_size;/* Space for the terminating zeros */ -size_t extra_size =2 * glyph_size; +const DWORD extra_size =2 * glyph_size;/* Check for enough space to convert this domain */ if (converted_size + domain_size + extra_size > buf_size)
@@ -2450,7 +2460,7 @@/* Set DNS Server address */ err =RegSetValueExA (rule_key,"GenericDNSServers" ,0 ,REG_SZ , (PBYTE )address, -strlen (address) +1 ); + (DWORD )strlen (address) +1 );if (err) { goto out;
@@ -2571,7 +2581,7 @@if (domains[0 ]) {size_t domains_len =strlen (domains); - dom_size = domains_len +2 ;/* len + the trailing NULs */ + dom_size = (DWORD )domains_len +2 ;/* len + the trailing NULs */ wide_domains =utf8to16_size (domains, dom_size); dom_size *=sizeof (*wide_domains);
@@ -2628,10 +2638,6 @@return err; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif -/** * Return the registry key where NRPT rules are stored *
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I864cd4a718886f437b72e93d0286f90fcb73592b
Gerrit-Change-Number: 1457
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Attention is currently required from: cron2, d12fk, plaisthos.
flichtenheld has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email )
Change subject: openvpnserv: Fix conversion warnings in interactive.c
......................................................................
Patch Set 4:
(2 comments)
File src/openvpnserv/interactive.c:
http://gerrit.openvpn.net/c/openvpn/+/1457/comment/cb480e29_6a268e34?usp=email :
PS3, Line 1391: RegWStringLength(PCWSTR string)
Quoted 1 line
I'd suggest to name that
RegWStringSize()- d12fk has tried to make everything that is a "number o […]
Done
http://gerrit.openvpn.net/c/openvpn/+/1457/comment/591009df_dff70458?usp=email :
PS3, Line 1744: static LSTATUS
Quoted 1 line
why is that change? We have a
DWORD errand return that?
Yeah, I started cleaning up DWORD vs LSTATUS. But didn't really finish it. Also not relevant right now since they are the same size, only differ in signedness. So removing all these changes and deferring them to later.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I864cd4a718886f437b72e93d0286f90fcb73592b
Gerrit-Change-Number: 1457
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Comment-Date: Fri, 09 Jan 2026 12:56:27 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Attention is currently required from: cron2, flichtenheld, plaisthos.
d12fk has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email )
Change subject: openvpnserv: Fix conversion warnings in interactive.c
......................................................................
Patch Set 4: Code-Review+2
(1 comment)
File src/openvpnserv/interactive.c:
http://gerrit.openvpn.net/c/openvpn/+/1457/comment/0e9049bb_dd642e67?usp=email :
PS4, Line 1387: * Return correct length for regex value to set for string I think you mean Registry not Regex
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I864cd4a718886f437b72e93d0286f90fcb73592b
Gerrit-Change-Number: 1457
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 19 Jan 2026 20:57:18 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
PATCH v4 1/1 openvpnserv: Fix conversion warnings in interactive.c
In reply to a message not in the archiveFrom: Frank Lichtenheld <[email protected]...>
Mostly DWORD vs. size_t conversions where we have no choice but to cast.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1457
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1457
This mail reflects revision 4 of this Change.
Acked-by according to Gerrit (reflected above):
Heiko Hund <[email protected]...>
src/openvpnserv/interactive.c +32 -26
@@ -1383,10 +1383,20 @@return TRUE; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif +/** +* Return correct length for regex value to set for string +* +*/ +static DWORD +RegWStringSize (PCWSTR string) +{ +size_t length = (wcslen (string) +1 ) *sizeof (wchar_t); +if (length >UINT_MAX ) + { + length =UINT_MAX ; + } +return (DWORD )length; +}/** * Prepare DNS domain "SearchList" registry value, so additional
@@ -1413,7 +1423,7 @@return TRUE; } -DWORD size = (wcslen (list) +1 ) *sizeof (*list); +DWORD size =RegWStringSize (list);LSTATUS err =RegSetValueExW (key,L"InitialSearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1474,7 +1484,7 @@wcsncpy (list, domains,wcslen (domains) +1 ); } - size = (wcslen (list) +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1515,7 +1525,7 @@ goto out; } - size = (wcslen (list) +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1579,14 +1589,14 @@ }/* If the search list is back to its initial state reset it */ -if (wcsncmp (list, initial,wcslen (list)) ==0 ) +if (wcsncmp (list, initial, list_len) ==0 ) {ResetDnsSearchDomains (key);return ; } } - size = (list_len +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1751,7 +1761,7 @@ goto out; } - err =RegSetValueExA (itf,"NameServer" ,0 ,REG_SZ , (PBYTE )value,strlen (value) +1 ); + err =RegSetValueExA (itf,"NameServer" ,0 ,REG_SZ , (PBYTE )value, (DWORD )strlen (value) +1 );if (err) { MsgToEventLog(M_SYSERR, L"%S: could not set name servers '%S' for %s family %d (%lu)",
@@ -1807,7 +1817,7 @@int addr_len = msg->addr_len;/* sanity check */ -const size_t max_addrs =_countof (msg->addr); +const int max_addrs =_countof (msg->addr);if (addr_len > max_addrs) { addr_len = max_addrs;
@@ -1949,7 +1959,7 @@short family = families[i];/* Create a comma sparated list of addresses of this family */ -int offset =0 ; +size_t offset =0 ;char addr_list[NRPT_ADDR_SIZE *NRPT_ADDR_NUM ];for (int j =0 ; j <NRPT_ADDR_NUM && addresses[j][0 ]; j++) {
@@ -2085,9 +2095,9 @@size_t addr_len =strlen (pos); pos += addr_len; - s -= addr_len; + s -= (DWORD )addr_len; } - s =strlen (addrs) +1 ; + s = (DWORD )strlen (addrs) +1 ; }if (strchr (addrs,':' ))
@@ -2163,7 +2173,8 @@LSTATUS err =ERROR_FILE_NOT_FOUND ;const DWORD buf_size = *size; -const size_t glyph_size =sizeof (*domains); +const DWORD glyph_size =sizeof (*domains); +const DWORD buf_len = buf_size / glyph_size;PWSTR values[] = {L"SearchList" ,L"Domain" ,L"DhcpDomainSearchList" ,L"DhcpDomain" ,NULL };for (int i =0 ; values[i]; i++)
@@ -2178,7 +2189,6 @@* - convert comma separated list to MULTI_SZ */ PWCHAR pos = domains; -const DWORD buf_len = buf_size / glyph_size;while (TRUE) {/* Terminate the domain at the next comma */
@@ -2188,9 +2198,9 @@ *comma ='\0' ; } -size_t domain_len =wcslen (pos); -size_t domain_size = domain_len * glyph_size; -size_t converted_size = (pos - domains) * glyph_size; +DWORD domain_len = (DWORD )wcslen (pos); +DWORD domain_size = domain_len * glyph_size; +DWORD converted_size = (DWORD )(pos - domains) * glyph_size;/* Ignore itf domains which match a pushed search domain */ if (ListContainsDomain (search_domains, pos, domain_len))
@@ -2216,7 +2226,7 @@ domain_size += glyph_size;/* Space for the terminating zeros */ -size_t extra_size =2 * glyph_size; +const DWORD extra_size =2 * glyph_size;/* Check for enough space to convert this domain */ if (converted_size + domain_size + extra_size > buf_size)
@@ -2450,7 +2460,7 @@/* Set DNS Server address */ err =RegSetValueExA (rule_key,"GenericDNSServers" ,0 ,REG_SZ , (PBYTE )address, -strlen (address) +1 ); + (DWORD )strlen (address) +1 );if (err) { goto out;
@@ -2571,7 +2581,7 @@if (domains[0 ]) {size_t domains_len =strlen (domains); - dom_size = domains_len +2 ;/* len + the trailing NULs */ + dom_size = (DWORD )domains_len +2 ;/* len + the trailing NULs */ wide_domains =utf8to16_size (domains, dom_size); dom_size *=sizeof (*wide_domains);
@@ -2628,10 +2638,6 @@return err; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif -/** * Return the registry key where NRPT rules are stored *
Attention is currently required from: cron2, d12fk, flichtenheld, plaisthos.
Hello cron2, d12fk, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email
to look at the new patch set (#5).
The following approvals got outdated and were removed:
Code-Review+2 by d12fk
The change is no longer submittable: Code-Review and checks~ChecksSubmitRule are unsatisfied now.
Change subject: openvpnserv: Fix conversion warnings in interactive.c
......................................................................
openvpnserv: Fix conversion warnings in interactive.c
Mostly DWORD vs. size_t conversions where we have no choice but to cast.
---
M src/openvpnserv/interactive.c
1 file changed, 32 insertions(+), 26 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/1457/5
src/openvpnserv/interactive.c +32 -26
@@ -1383,10 +1383,20 @@return TRUE; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif +/** +* Return correct size for registry value to set for string +* +*/ +static DWORD +RegWStringSize (PCWSTR string) +{ +size_t length = (wcslen (string) +1 ) *sizeof (wchar_t); +if (length >UINT_MAX ) + { + length =UINT_MAX ; + } +return (DWORD )length; +}/** * Prepare DNS domain "SearchList" registry value, so additional
@@ -1413,7 +1423,7 @@return TRUE; } -DWORD size = (wcslen (list) +1 ) *sizeof (*list); +DWORD size =RegWStringSize (list);LSTATUS err =RegSetValueExW (key,L"InitialSearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1474,7 +1484,7 @@wcsncpy (list, domains,wcslen (domains) +1 ); } - size = (wcslen (list) +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1515,7 +1525,7 @@ goto out; } - size = (wcslen (list) +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1579,14 +1589,14 @@ }/* If the search list is back to its initial state reset it */ -if (wcsncmp (list, initial,wcslen (list)) ==0 ) +if (wcsncmp (list, initial, list_len) ==0 ) {ResetDnsSearchDomains (key);return ; } } - size = (list_len +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1751,7 +1761,7 @@ goto out; } - err =RegSetValueExA (itf,"NameServer" ,0 ,REG_SZ , (PBYTE )value,strlen (value) +1 ); + err =RegSetValueExA (itf,"NameServer" ,0 ,REG_SZ , (PBYTE )value, (DWORD )strlen (value) +1 );if (err) { MsgToEventLog(M_SYSERR, L"%S: could not set name servers '%S' for %s family %d (%lu)",
@@ -1807,7 +1817,7 @@int addr_len = msg->addr_len;/* sanity check */ -const size_t max_addrs =_countof (msg->addr); +const int max_addrs =_countof (msg->addr);if (addr_len > max_addrs) { addr_len = max_addrs;
@@ -1949,7 +1959,7 @@short family = families[i];/* Create a comma sparated list of addresses of this family */ -int offset =0 ; +size_t offset =0 ;char addr_list[NRPT_ADDR_SIZE *NRPT_ADDR_NUM ];for (int j =0 ; j <NRPT_ADDR_NUM && addresses[j][0 ]; j++) {
@@ -2085,9 +2095,9 @@size_t addr_len =strlen (pos); pos += addr_len; - s -= addr_len; + s -= (DWORD )addr_len; } - s =strlen (addrs) +1 ; + s = (DWORD )strlen (addrs) +1 ; }if (strchr (addrs,':' ))
@@ -2163,7 +2173,8 @@LSTATUS err =ERROR_FILE_NOT_FOUND ;const DWORD buf_size = *size; -const size_t glyph_size =sizeof (*domains); +const DWORD glyph_size =sizeof (*domains); +const DWORD buf_len = buf_size / glyph_size;PWSTR values[] = {L"SearchList" ,L"Domain" ,L"DhcpDomainSearchList" ,L"DhcpDomain" ,NULL };for (int i =0 ; values[i]; i++)
@@ -2178,7 +2189,6 @@* - convert comma separated list to MULTI_SZ */ PWCHAR pos = domains; -const DWORD buf_len = buf_size / glyph_size;while (TRUE) {/* Terminate the domain at the next comma */
@@ -2188,9 +2198,9 @@ *comma ='\0' ; } -size_t domain_len =wcslen (pos); -size_t domain_size = domain_len * glyph_size; -size_t converted_size = (pos - domains) * glyph_size; +DWORD domain_len = (DWORD )wcslen (pos); +DWORD domain_size = domain_len * glyph_size; +DWORD converted_size = (DWORD )(pos - domains) * glyph_size;/* Ignore itf domains which match a pushed search domain */ if (ListContainsDomain (search_domains, pos, domain_len))
@@ -2216,7 +2226,7 @@ domain_size += glyph_size;/* Space for the terminating zeros */ -size_t extra_size =2 * glyph_size; +const DWORD extra_size =2 * glyph_size;/* Check for enough space to convert this domain */ if (converted_size + domain_size + extra_size > buf_size)
@@ -2450,7 +2460,7 @@/* Set DNS Server address */ err =RegSetValueExA (rule_key,"GenericDNSServers" ,0 ,REG_SZ , (PBYTE )address, -strlen (address) +1 ); + (DWORD )strlen (address) +1 );if (err) { goto out;
@@ -2571,7 +2581,7 @@if (domains[0 ]) {size_t domains_len =strlen (domains); - dom_size = domains_len +2 ;/* len + the trailing NULs */ + dom_size = (DWORD )domains_len +2 ;/* len + the trailing NULs */ wide_domains =utf8to16_size (domains, dom_size); dom_size *=sizeof (*wide_domains);
@@ -2628,10 +2638,6 @@return err; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif -/** * Return the registry key where NRPT rules are stored *
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I864cd4a718886f437b72e93d0286f90fcb73592b
Gerrit-Change-Number: 1457
Gerrit-PatchSet: 5
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Attention is currently required from: cron2, d12fk, plaisthos.
flichtenheld has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email )
Change subject: openvpnserv: Fix conversion warnings in interactive.c
......................................................................
Patch Set 5:
(1 comment)
File src/openvpnserv/interactive.c:
http://gerrit.openvpn.net/c/openvpn/+/1457/comment/834b3ca5_a2c05ba2?usp=email :
PS4, Line 1387: * Return correct length for regex value to set for string
Quoted 1 line
I think you mean Registry not Regex
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I864cd4a718886f437b72e93d0286f90fcb73592b
Gerrit-Change-Number: 1457
Gerrit-PatchSet: 5
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Comment-Date: Tue, 20 Jan 2026 12:00:27 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: d12fk <[email protected]...>
Attention is currently required from: cron2, flichtenheld, plaisthos.
d12fk has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email )
Change subject: openvpnserv: Fix conversion warnings in interactive.c
......................................................................
Patch Set 5: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I864cd4a718886f437b72e93d0286f90fcb73592b
Gerrit-Change-Number: 1457
Gerrit-PatchSet: 5
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 20 Jan 2026 14:52:32 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
PATCH v5 1/1 openvpnserv: Fix conversion warnings in interactive.c
In reply to a message not in the archiveMostly DWORD vs. size_t conversions where we have no choice but to cast.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1457
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1457
This mail reflects revision 5 of this Change.
Acked-by according to Gerrit (reflected above):
Heiko Hund <[email protected]...>
src/openvpnserv/interactive.c +32 -26
@@ -1383,10 +1383,20 @@return TRUE; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif +/** +* Return correct size for registry value to set for string +* +*/ +static DWORD +RegWStringSize (PCWSTR string) +{ +size_t length = (wcslen (string) +1 ) *sizeof (wchar_t); +if (length >UINT_MAX ) + { + length =UINT_MAX ; + } +return (DWORD )length; +}/** * Prepare DNS domain "SearchList" registry value, so additional
@@ -1413,7 +1423,7 @@return TRUE; } -DWORD size = (wcslen (list) +1 ) *sizeof (*list); +DWORD size =RegWStringSize (list);LSTATUS err =RegSetValueExW (key,L"InitialSearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1474,7 +1484,7 @@wcsncpy (list, domains,wcslen (domains) +1 ); } - size = (wcslen (list) +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1515,7 +1525,7 @@ goto out; } - size = (wcslen (list) +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1579,14 +1589,14 @@ }/* If the search list is back to its initial state reset it */ -if (wcsncmp (list, initial,wcslen (list)) ==0 ) +if (wcsncmp (list, initial, list_len) ==0 ) {ResetDnsSearchDomains (key);return ; } } - size = (list_len +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1751,7 +1761,7 @@ goto out; } - err =RegSetValueExA (itf,"NameServer" ,0 ,REG_SZ , (PBYTE )value,strlen (value) +1 ); + err =RegSetValueExA (itf,"NameServer" ,0 ,REG_SZ , (PBYTE )value, (DWORD )strlen (value) +1 );if (err) { MsgToEventLog(M_SYSERR, L"%S: could not set name servers '%S' for %s family %d (%lu)",
@@ -1807,7 +1817,7 @@int addr_len = msg->addr_len;/* sanity check */ -const size_t max_addrs =_countof (msg->addr); +const int max_addrs =_countof (msg->addr);if (addr_len > max_addrs) { addr_len = max_addrs;
@@ -1949,7 +1959,7 @@short family = families[i];/* Create a comma sparated list of addresses of this family */ -int offset =0 ; +size_t offset =0 ;char addr_list[NRPT_ADDR_SIZE *NRPT_ADDR_NUM ];for (int j =0 ; j <NRPT_ADDR_NUM && addresses[j][0 ]; j++) {
@@ -2085,9 +2095,9 @@size_t addr_len =strlen (pos); pos += addr_len; - s -= addr_len; + s -= (DWORD )addr_len; } - s =strlen (addrs) +1 ; + s = (DWORD )strlen (addrs) +1 ; }if (strchr (addrs,':' ))
@@ -2163,7 +2173,8 @@LSTATUS err =ERROR_FILE_NOT_FOUND ;const DWORD buf_size = *size; -const size_t glyph_size =sizeof (*domains); +const DWORD glyph_size =sizeof (*domains); +const DWORD buf_len = buf_size / glyph_size;PWSTR values[] = {L"SearchList" ,L"Domain" ,L"DhcpDomainSearchList" ,L"DhcpDomain" ,NULL };for (int i =0 ; values[i]; i++)
@@ -2178,7 +2189,6 @@* - convert comma separated list to MULTI_SZ */ PWCHAR pos = domains; -const DWORD buf_len = buf_size / glyph_size;while (TRUE) {/* Terminate the domain at the next comma */
@@ -2188,9 +2198,9 @@ *comma ='\0' ; } -size_t domain_len =wcslen (pos); -size_t domain_size = domain_len * glyph_size; -size_t converted_size = (pos - domains) * glyph_size; +DWORD domain_len = (DWORD )wcslen (pos); +DWORD domain_size = domain_len * glyph_size; +DWORD converted_size = (DWORD )(pos - domains) * glyph_size;/* Ignore itf domains which match a pushed search domain */ if (ListContainsDomain (search_domains, pos, domain_len))
@@ -2216,7 +2226,7 @@ domain_size += glyph_size;/* Space for the terminating zeros */ -size_t extra_size =2 * glyph_size; +const DWORD extra_size =2 * glyph_size;/* Check for enough space to convert this domain */ if (converted_size + domain_size + extra_size > buf_size)
@@ -2450,7 +2460,7 @@/* Set DNS Server address */ err =RegSetValueExA (rule_key,"GenericDNSServers" ,0 ,REG_SZ , (PBYTE )address, -strlen (address) +1 ); + (DWORD )strlen (address) +1 );if (err) { goto out;
@@ -2571,7 +2581,7 @@if (domains[0 ]) {size_t domains_len =strlen (domains); - dom_size = domains_len +2 ;/* len + the trailing NULs */ + dom_size = (DWORD )domains_len +2 ;/* len + the trailing NULs */ wide_domains =utf8to16_size (domains, dom_size); dom_size *=sizeof (*wide_domains);
@@ -2628,10 +2638,6 @@return err; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif -/** * Return the registry key where NRPT rules are stored *
[Openvpn-devel] [PATCH applied] Re: openvpnserv: Fix conversion warnings in interactive.c
This is windows related, so I can't really test this (beyond "does it compile?"). Took a few attempts discussing "length" and "size", but now everbody seems to be happy - thanks to Heiko for the review.
(I do think "length" inside RegWStringSize() should also be named "size", though, but that can be done in a followup patch - proceeding here, because I want the unit tests in, and this is prerequisite)
Your patch has been applied to the master branch.
commit fdfe0abeefaf74a0be011688af068929cbd9d246
Author: Frank Lichtenheld Date: Tue Jan 20 16:55:47 2026 +0100
openvpnserv: Fix conversion warnings in interactive.c
Signed-off-by: Frank Lichtenheld <[email protected]...>
Acked-by: Heiko Hund <[email protected]...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1457
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35356.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#6) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by d12fk
Change subject: openvpnserv: Fix conversion warnings in interactive.c
......................................................................
openvpnserv: Fix conversion warnings in interactive.c
Mostly DWORD vs. size_t conversions where we have no choice but to cast.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1457
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35356.html
---
M src/openvpnserv/interactive.c
1 file changed, 32 insertions(+), 26 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/1457/6
src/openvpnserv/interactive.c +32 -26
@@ -1383,10 +1383,20 @@return TRUE; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif +/** +* Return correct size for registry value to set for string +* +*/ +static DWORD +RegWStringSize (PCWSTR string) +{ +size_t length = (wcslen (string) +1 ) *sizeof (wchar_t); +if (length >UINT_MAX ) + { + length =UINT_MAX ; + } +return (DWORD )length; +}/** * Prepare DNS domain "SearchList" registry value, so additional
@@ -1413,7 +1423,7 @@return TRUE; } -DWORD size = (wcslen (list) +1 ) *sizeof (*list); +DWORD size =RegWStringSize (list);LSTATUS err =RegSetValueExW (key,L"InitialSearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1474,7 +1484,7 @@wcsncpy (list, domains,wcslen (domains) +1 ); } - size = (wcslen (list) +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1515,7 +1525,7 @@ goto out; } - size = (wcslen (list) +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1579,14 +1589,14 @@ }/* If the search list is back to its initial state reset it */ -if (wcsncmp (list, initial,wcslen (list)) ==0 ) +if (wcsncmp (list, initial, list_len) ==0 ) {ResetDnsSearchDomains (key);return ; } } - size = (list_len +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1751,7 +1761,7 @@ goto out; } - err =RegSetValueExA (itf,"NameServer" ,0 ,REG_SZ , (PBYTE )value,strlen (value) +1 ); + err =RegSetValueExA (itf,"NameServer" ,0 ,REG_SZ , (PBYTE )value, (DWORD )strlen (value) +1 );if (err) { MsgToEventLog(M_SYSERR, L"%S: could not set name servers '%S' for %s family %d (%lu)",
@@ -1807,7 +1817,7 @@int addr_len = msg->addr_len;/* sanity check */ -const size_t max_addrs =_countof (msg->addr); +const int max_addrs =_countof (msg->addr);if (addr_len > max_addrs) { addr_len = max_addrs;
@@ -1949,7 +1959,7 @@short family = families[i];/* Create a comma sparated list of addresses of this family */ -int offset =0 ; +size_t offset =0 ;char addr_list[NRPT_ADDR_SIZE *NRPT_ADDR_NUM ];for (int j =0 ; j <NRPT_ADDR_NUM && addresses[j][0 ]; j++) {
@@ -2085,9 +2095,9 @@size_t addr_len =strlen (pos); pos += addr_len; - s -= addr_len; + s -= (DWORD )addr_len; } - s =strlen (addrs) +1 ; + s = (DWORD )strlen (addrs) +1 ; }if (strchr (addrs,':' ))
@@ -2163,7 +2173,8 @@LSTATUS err =ERROR_FILE_NOT_FOUND ;const DWORD buf_size = *size; -const size_t glyph_size =sizeof (*domains); +const DWORD glyph_size =sizeof (*domains); +const DWORD buf_len = buf_size / glyph_size;PWSTR values[] = {L"SearchList" ,L"Domain" ,L"DhcpDomainSearchList" ,L"DhcpDomain" ,NULL };for (int i =0 ; values[i]; i++)
@@ -2178,7 +2189,6 @@* - convert comma separated list to MULTI_SZ */ PWCHAR pos = domains; -const DWORD buf_len = buf_size / glyph_size;while (TRUE) {/* Terminate the domain at the next comma */
@@ -2188,9 +2198,9 @@ *comma ='\0' ; } -size_t domain_len =wcslen (pos); -size_t domain_size = domain_len * glyph_size; -size_t converted_size = (pos - domains) * glyph_size; +DWORD domain_len = (DWORD )wcslen (pos); +DWORD domain_size = domain_len * glyph_size; +DWORD converted_size = (DWORD )(pos - domains) * glyph_size;/* Ignore itf domains which match a pushed search domain */ if (ListContainsDomain (search_domains, pos, domain_len))
@@ -2216,7 +2226,7 @@ domain_size += glyph_size;/* Space for the terminating zeros */ -size_t extra_size =2 * glyph_size; +const DWORD extra_size =2 * glyph_size;/* Check for enough space to convert this domain */ if (converted_size + domain_size + extra_size > buf_size)
@@ -2450,7 +2460,7 @@/* Set DNS Server address */ err =RegSetValueExA (rule_key,"GenericDNSServers" ,0 ,REG_SZ , (PBYTE )address, -strlen (address) +1 ); + (DWORD )strlen (address) +1 );if (err) { goto out;
@@ -2571,7 +2581,7 @@if (domains[0 ]) {size_t domains_len =strlen (domains); - dom_size = domains_len +2 ;/* len + the trailing NULs */ + dom_size = (DWORD )domains_len +2 ;/* len + the trailing NULs */ wide_domains =utf8to16_size (domains, dom_size); dom_size *=sizeof (*wide_domains);
@@ -2628,10 +2638,6 @@return err; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif -/** * Return the registry key where NRPT rules are stored *
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I864cd4a718886f437b72e93d0286f90fcb73592b
Gerrit-Change-Number: 1457
Gerrit-PatchSet: 6
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email )
Change subject: openvpnserv: Fix conversion warnings in interactive.c
......................................................................
openvpnserv: Fix conversion warnings in interactive.c
Mostly DWORD vs. size_t conversions where we have no choice but to cast.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1457
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35356.html
---
M src/openvpnserv/interactive.c
1 file changed, 32 insertions(+), 26 deletions(-)
src/openvpnserv/interactive.c +32 -26
@@ -1383,10 +1383,20 @@return TRUE; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif +/** +* Return correct size for registry value to set for string +* +*/ +static DWORD +RegWStringSize (PCWSTR string) +{ +size_t length = (wcslen (string) +1 ) *sizeof (wchar_t); +if (length >UINT_MAX ) + { + length =UINT_MAX ; + } +return (DWORD )length; +}/** * Prepare DNS domain "SearchList" registry value, so additional
@@ -1413,7 +1423,7 @@return TRUE; } -DWORD size = (wcslen (list) +1 ) *sizeof (*list); +DWORD size =RegWStringSize (list);LSTATUS err =RegSetValueExW (key,L"InitialSearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1474,7 +1484,7 @@wcsncpy (list, domains,wcslen (domains) +1 ); } - size = (wcslen (list) +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1515,7 +1525,7 @@ goto out; } - size = (wcslen (list) +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1579,14 +1589,14 @@ }/* If the search list is back to its initial state reset it */ -if (wcsncmp (list, initial,wcslen (list)) ==0 ) +if (wcsncmp (list, initial, list_len) ==0 ) {ResetDnsSearchDomains (key);return ; } } - size = (list_len +1 ) *sizeof (list[0 ]); + size =RegWStringSize (list); err =RegSetValueExW (key,L"SearchList" ,0 ,REG_SZ , (PBYTE )list, size);if (err) {
@@ -1751,7 +1761,7 @@ goto out; } - err =RegSetValueExA (itf,"NameServer" ,0 ,REG_SZ , (PBYTE )value,strlen (value) +1 ); + err =RegSetValueExA (itf,"NameServer" ,0 ,REG_SZ , (PBYTE )value, (DWORD )strlen (value) +1 );if (err) { MsgToEventLog(M_SYSERR, L"%S: could not set name servers '%S' for %s family %d (%lu)",
@@ -1807,7 +1817,7 @@int addr_len = msg->addr_len;/* sanity check */ -const size_t max_addrs =_countof (msg->addr); +const int max_addrs =_countof (msg->addr);if (addr_len > max_addrs) { addr_len = max_addrs;
@@ -1949,7 +1959,7 @@short family = families[i];/* Create a comma sparated list of addresses of this family */ -int offset =0 ; +size_t offset =0 ;char addr_list[NRPT_ADDR_SIZE *NRPT_ADDR_NUM ];for (int j =0 ; j <NRPT_ADDR_NUM && addresses[j][0 ]; j++) {
@@ -2085,9 +2095,9 @@size_t addr_len =strlen (pos); pos += addr_len; - s -= addr_len; + s -= (DWORD )addr_len; } - s =strlen (addrs) +1 ; + s = (DWORD )strlen (addrs) +1 ; }if (strchr (addrs,':' ))
@@ -2163,7 +2173,8 @@LSTATUS err =ERROR_FILE_NOT_FOUND ;const DWORD buf_size = *size; -const size_t glyph_size =sizeof (*domains); +const DWORD glyph_size =sizeof (*domains); +const DWORD buf_len = buf_size / glyph_size;PWSTR values[] = {L"SearchList" ,L"Domain" ,L"DhcpDomainSearchList" ,L"DhcpDomain" ,NULL };for (int i =0 ; values[i]; i++)
@@ -2178,7 +2189,6 @@* - convert comma separated list to MULTI_SZ */ PWCHAR pos = domains; -const DWORD buf_len = buf_size / glyph_size;while (TRUE) {/* Terminate the domain at the next comma */
@@ -2188,9 +2198,9 @@ *comma ='\0' ; } -size_t domain_len =wcslen (pos); -size_t domain_size = domain_len * glyph_size; -size_t converted_size = (pos - domains) * glyph_size; +DWORD domain_len = (DWORD )wcslen (pos); +DWORD domain_size = domain_len * glyph_size; +DWORD converted_size = (DWORD )(pos - domains) * glyph_size;/* Ignore itf domains which match a pushed search domain */ if (ListContainsDomain (search_domains, pos, domain_len))
@@ -2216,7 +2226,7 @@ domain_size += glyph_size;/* Space for the terminating zeros */ -size_t extra_size =2 * glyph_size; +const DWORD extra_size =2 * glyph_size;/* Check for enough space to convert this domain */ if (converted_size + domain_size + extra_size > buf_size)
@@ -2450,7 +2460,7 @@/* Set DNS Server address */ err =RegSetValueExA (rule_key,"GenericDNSServers" ,0 ,REG_SZ , (PBYTE )address, -strlen (address) +1 ); + (DWORD )strlen (address) +1 );if (err) { goto out;
@@ -2571,7 +2581,7 @@if (domains[0 ]) {size_t domains_len =strlen (domains); - dom_size = domains_len +2 ;/* len + the trailing NULs */ + dom_size = (DWORD )domains_len +2 ;/* len + the trailing NULs */ wide_domains =utf8to16_size (domains, dom_size); dom_size *=sizeof (*wide_domains);
@@ -2628,10 +2638,6 @@return err; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif -/** * Return the registry key where NRPT rules are stored *
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1457?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I864cd4a718886f437b72e93d0286f90fcb73592b
Gerrit-Change-Number: 1457
Gerrit-PatchSet: 6
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>